package lab03.test08;

import java.io.*;

public class Test {
    public static void main(String[] args) {
        String path1 = "E:\\java  test\\lab03test08\\1.txt";
        String path2 = "E:\\java  test\\lab03test08\\2.txt";
        String path3 = "E:\\java  test\\lab03test08\\3.txt";


        FileOutputStream output = null;
        FileInputStream input1 = null;
        FileInputStream input2 =null;
        BufferedReader bufferedReader = null;

        try {
            input1 = new  FileInputStream(path1);
            input2 = new  FileInputStream(path2);
            output = new FileOutputStream(path3);

            int data1= 0;
            int data2= 0 ;

            String line = "";


            while (true) {
                if ((data1=input1.read()) != -1 && (data2=input2.read()) != -1) {
                    output.write(data1);
                    output.write(data2);
                } else if ((data1=input1.read()) != -1 && (data2=input2.read()) == -1) {
                    output.write(data1);
                } else if ((data1=input1.read()) == -1 && (data2=input2.read()) != -1) {
                    output.write(data2);
                }else if ((data1=input1.read()) == -1 && (data2=input2.read()) == -1){
                    break;
                }

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                input1.close();
                input2.close();
                output.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}
